package com.compass.doctor.ui.mine.view

import android.content.Context
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.compass.doctor.databinding.ViewDoctorInfoBinding
import com.compass.doctor.ui.mine.EditingInformationActivity
import com.compass.doctor.ui.mine.QRCodeActivity
import com.compass.framework.ext.onClick
import com.compass.framework.ext.toJson
import com.compass.framework.glide.setUrlCircle
import com.compass.framework.manager.UserInfoManager
import com.compass.framework.model.User

import com.compass.framework.utils.LogUtil
import com.netease.yunxin.kit.corekit.im.model.UserField
import com.netease.yunxin.kit.corekit.im.provider.FetchCallback
import com.netease.yunxin.kit.corekit.im.repo.CommonRepo

/**
 * Description：医生基本信息 view
 * Date:2023/12/6 16:39
 */
class DoctorInfoView(context: Context, type: Int?) : LinearLayout(context) {
    private var viewDoctorInfoBinding: ViewDoctorInfoBinding? = null


    init {
        viewDoctorInfoBinding =
            ViewDoctorInfoBinding.inflate(LayoutInflater.from(context), this, true)
        if (type == 1) {
            viewDoctorInfoBinding?.bindPatient?.visibility = VISIBLE
            viewDoctorInfoBinding?.mineNext?.visibility = GONE
        } else {
            viewDoctorInfoBinding?.bindPatient?.visibility = GONE
            viewDoctorInfoBinding?.mineNext?.visibility = VISIBLE
        }

        viewDoctorInfoBinding?.mineNext?.onClick {
            EditingInformationActivity.start(context)
        }

        viewDoctorInfoBinding?.bindPatient?.onClick {
            QRCodeActivity.start(context)
        }


    }

    fun setDoctorInfo(user: User?) {
        LogUtil.e("云信账号==${UserInfoManager.getImUserAccount()}")
        user?.let {
            viewDoctorInfoBinding?.apply {
                doctorName.text = it.getNameString()
                ivHead.setUrlCircle(it.avatar)
                positionName.text = it.getPositionNameString()
                departmentName.text = it.getDepartmentNameString()
            }
            UserInfoManager.saveMeetingUUID(it.wyyxUser?.userUuid)
            UserInfoManager.saveCA(it.signFile)
            UserInfoManager.saveMeetingToken(it.wyyxUser?.userToken)

            //  0待审核    1审核中    2已通过  -1已拒绝
            when(it.auditStatus){
                0->{
                    viewDoctorInfoBinding?.authentication?.text="待审核"
                }
                1->{
                    viewDoctorInfoBinding?.authentication?.text="平台审核中"
                }
                2->{
                    viewDoctorInfoBinding?.authentication?.text="平台已认证"
                }
                -1->{
                    viewDoctorInfoBinding?.authentication?.text="认证未通过"
                }
            }

        }

    }



}